home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / FILL.CPP < prev    next >
Text File  |  1997-05-06  |  908b  |  47 lines

  1.  #include <algorithm>
  2.  #include <vector>    
  3.  
  4.  using namespace std;
  5.  
  6.  int main ()
  7.  {
  8.    int d1[4] = {1,2,3,4};
  9.    //
  10.    // Set up two vectors.
  11.    //
  12.    vector<int> v1(d1+0, d1+4), v2(d1+0, d1+4);
  13.    //
  14.    // Set up one empty vector.
  15.    //
  16.    vector<int> v3;
  17.    //
  18.    // Fill all of v1 with 9.
  19.    //
  20.    fill(v1.begin(), v1.end(), 9);
  21.    //
  22.    // Fill first 3 of v2 with 7.
  23.    //
  24.    fill_n(v2.begin(), 3, 7);
  25.    //
  26.    // Use insert iterator to fill v3 with 5 11's.
  27.    //
  28.    fill_n(back_inserter(v3), 5, 11);
  29.    //
  30.    // Copy all three to cout.
  31.    //
  32.    ostream_iterator<int> out(cout," ");
  33.    copy(v1.begin(),v1.end(),out);
  34.    cout << endl;
  35.    copy(v2.begin(),v2.end(),out);
  36.    cout << endl;
  37.    copy(v3.begin(),v3.end(),out);
  38.    cout << endl;
  39.    //
  40.    // Fill cout with 3 5's.
  41.    //
  42.    fill_n(ostream_iterator<int>(cout," "), 3, 5);
  43.    cout << endl;
  44.  
  45.    return 0;
  46.  }
  47.